﻿using Common;
using Common.Dtos;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sigma.Admin.Client.Services
{
    public class UserService : IUserService
    {
        private readonly HttpRestClient _client;
        private readonly string service = "User";

        public UserService(HttpRestClient client)
        {
            _client = client;
        }

        public async Task<ApiResponse<List<UsersDto>>> GetAllUser()
        {
            var url = $"api/{service}/GetAllUser";
            var request = BaseRequest.HttpGet(url);
            var res = await _client.ExecuteAsync<List<UsersDto>>(request);
            
            return res;
        }
        
        public async Task<ApiResponse> AddUser(UsersDto user)
        {
            var url = $"api/{service}/AddUser";
            var request = BaseRequest.HttpPost(url,user);
            var res = await _client.ExecuteAsync(request);
            return res;
        }

        public async Task<ApiResponse> UpdateUsers(List<UsersDto> user)
        {
            var url = $"api/{service}/UpdateUser";
            var request = BaseRequest.HttpPost(url, user);
            var res = await _client.ExecuteAsync(request);
            return res;
        }

        public async Task<ApiResponse> EditPKey(UsersDto user)
        {
            var url = $"api/{service}/EditPKey";
            var request = BaseRequest.HttpPost(url, user);
            var res = await _client.ExecuteAsync(request);
            return res;
        }

        public async Task<ApiResponse> DeleteUsers(List<UsersDto> user)
        {
            var url = $"api/{service}/DeleteUser";
            var request = BaseRequest.HttpPost(url, user);
            var res = await _client.ExecuteAsync(request);
            return res;
        }
    }
}
